package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    // 根据分类id统计菜品数量
    @Select("select count(*) from dish where category_id=#{cid}")
    Integer countByCategoryId(Long cid);

    // 条件查询
    List<DishVO> findList(DishPageDTO dto);

    // 新增菜品
    @AutoFill("insert")// 自动填充
    @Options(useGeneratedKeys = true,keyProperty = "id")// 主键返回
    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Dish dish);

    // 查询菜品
    @Select("select d.*,c.name categoryName from dish d left join category c on d.category_id = c.id where d.id=#{id}")
    DishVO findById(Long id);

    // 修改菜品
    void update(Dish dish);

    // 删除菜品
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);
}
